package com.aaa.mythread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class MyThread3 implements Callable<String> {
    @Override
    public String call() throws Exception {
        // 业务
        for (int i = 0; i < 5; i++) {
            System.out.println("数字是:"+i);

        }

        return "任务执行完毕";
    }


    public static void main(String[] args) {
        MyThread3 myThread3 = new MyThread3();
        // 获取返回值
        FutureTask<String> futureTask = new FutureTask<>(myThread3);

        //
        Thread thread = new Thread(futureTask);
        thread.start();
        try {
            String s = futureTask.get();
            System.out.println("返回的结果是:"+s);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }
}
